package com.qc31.monitorlib.ui.stopcar

import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.qc31.baselib.base.BaseRecycleActivity
import com.qc31.baselib.custom.LeftRightTextView
import com.qc31.baselib.utils.ToolbarHelper
import com.qc31.comlib.Keys
import com.qc31.comlib.entity.StopStats
import com.qc31.monitorlib.R
import com.qc31.monitorlib.databinding.ActivityToolbarListBinding

/** @Author Jasper @Time 2020/12/11 @Desc 停车报警详情 */
class StopCarDetailActivity :
    BaseRecycleActivity<ActivityToolbarListBinding>(ActivityToolbarListBinding::inflate) {
    private val mAdapter by lazy { StopCarDetailAdapter() }

    override fun initView() {
        super.initView()
        val title = intent.getStringExtra(Keys.INTENT_TITLE)!!
        val data: ArrayList<StopStats.StopInfo.StopDetail> =
            intent.getParcelableArrayListExtra(Keys.INTENT_DATA)!!
        ToolbarHelper.setToolbar(this, title)

        mRecyclerVB.recyclerView.layoutManager = LinearLayoutManager(this)
        mRecyclerVB.recyclerView.adapter = mAdapter
        mAdapter.setList(data)
    }

    override fun setListener() {

    }

    inner class StopCarDetailAdapter :
        BaseQuickAdapter<StopStats.StopInfo.StopDetail, BaseViewHolder>(R.layout.item_stop_car_detail) {
        override fun convert(holder: BaseViewHolder, item: StopStats.StopInfo.StopDetail) {
            item.run {
                val position = holder.layoutPosition + 1
                val num = if (position < 10) "0$position" else "$position"
                holder.setText(R.id.tv_item_num, num)
                holder.setText(R.id.tv_address, addr)
                holder.getView<LeftRightTextView>(R.id.lr_tv_stop_start_time)
                    .setRightText(stime)
                holder.getView<LeftRightTextView>(R.id.lr_tv_stop_end_time)
                    .setRightText(etime)
                holder.getView<LeftRightTextView>(R.id.lr_tv_stop_detail_long)
                    .setRightText(long)
            }
        }
    }
}